<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>物料信息</title>
    <th:block th:include="material/core/resources::headers"/>
</head>
<body>

<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">物料监控</a>
            <a href="">物料收入</a>
            <a><cite>展示</cite></a>
          </span>

    <div class="layui-inline layui-show-xs-block" style="margin-left: 750px">
        <input type="text" name="info" id="info" placeholder="请输入信息" autocomplete="off"
               class="layui-input">
    </div>
    <div class="layui-inline layui-show-xs-block">
        <button class="layui-btn" lay-submit="sreachMi" lay-filter="sreachMi" onclick="sreachMi();return false;"><i
                class="layui-icon">&#xe615;</i></button>
    </div>

    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>

<!-- 内容部分-->
<div class="layui-card-body ">
    <table class="layui-hide" id="MiList" lay-filter="MiSub"></table>
</div>

</body>

<script>
    layui.use('table', function () {

        var table = layui.table;

        table.render({
            height: 512,
            elem: '#MiList',
            url: '/mi/list',
            toolbar: 'default',
            method: 'post',
            page: true,
            cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'miId', title: '物料收入编号', width: 80, sort: true, align: 'center', templet: '#mi_id'},
                    {field: 'mId', title: '物料', align: 'center', templet: '#m_id'},
                    {field: 'miQuantity', title: '剩余数量', align: 'center', templet: '#mi_quantity'},
                    {field: 'miDate', title: '收入日期', align: 'center'},
                    {field: 'miSender', title: '发送人', sort: true, align: 'center', templet: '#mi_Sender'},
                    {field: 'miReceiver', title: '接受人', align: 'center', templet: '#mi_Receiver'},
                    {field: 'miRemark', title: '备注', align: 'center', templet: '#mi_Remark'},
                ]
            ],
            parseData(res) {
                return {
                    "code": res.success ? 0 : 300,
                    "count": res.data.total,
                    "data": res.data.list
                }
            }
        });
        table.on('toolbar(MiSub)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    xadmin.open('添加物料收入', '/mi/insert', 800, 600);
                    break;
                case 'update':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else if (data.length > 1) {
                        layer.msg('只能同时编辑一个');
                    } else {
                        xadmin.open('编辑物料收入', '/mi/update?id=' + data[0].miId, 800, 600);
                    }
                    break;
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else if (data.length === 1) {
                        /***********删除*************/
                        layer.confirm('确认要删除吗？', function () {
                            $.ajax({
                                url: pathPrefix + '/mi/delete/' + data[0].miId,
                                type: 'delete',
                                success(data) {
                                    if (data.success) {
                                        $(obj).parents("tr").remove();
                                        layer.msg("删除成功", {icon: 1, time: 1000},
                                            function () {
                                                location.reload();
                                            });
                                    }
                                }
                            })
                            return false;
                        });
                    } else {
                        layer.msg('给我一个一个删！😡');
                    }
                    break;
            }
            ;
        });

        //监听行工具事件
        table.on('tool(MiSub)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                layer.msg('查看操作');
            } else if (layEvent === 'more') {
                //下拉菜单
                dropdown.render({
                    elem: this //触发事件的 DOM 对象
                    , show: true //外部事件触发即显示
                    , data: [{
                        title: '编辑'
                        , id: 'edit'
                    }, {
                        title: '删除'
                        , id: 'del'
                    }]
                    , click: function (menudata) {
                        if (menudata.id === 'del') {
                            layer.confirm('真的删除行么', function (index) {
                                obj.del(); //删除对应行（tr）的DOM结构
                                layer.close(index);
                                //向服务端发送删除指令
                            });
                        } else if (menudata.id === 'edit') {
                            layer.msg('编辑操作，当前行 ID:' + data.id);
                        }
                    }
                    , align: 'right' //右对齐弹出（v2.6.8 新增）
                    , style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                })
            }
        });
    });
</script>


<script>
    function sreachMi() {
        const info = $("#info").val();
        alert("查询的物料收入编号为：" + info);
        layui.use('table', function () {
            const table = layui.table;
            debugger
            table.render({
                height: 512,
                elem: '#MiList',
                url: '/mi/select/' + info,
                method: 'post',
                page: true,
                cols: [
                    [
                        {type: 'checkbox', fixed: 'left'},
                        {field: 'miId', title: '物料收入编号', width: 80, sort: true, align: 'center'},
                        {field: 'mId', title: '物料', align: 'center'},
                        {field: 'miQuantity', title: '剩余数量', align: 'center'},
                        {field: 'miDate', title: '收入日期', align: 'center'},
                        {field: 'miSender', title: '发送人', sort: true, align: 'center'},
                        {field: 'miReceiver', title: '接受人', align: 'center'},
                        {field: 'miRemark', title: '备注', align: 'center'},
                    ]
                ],
                parseData(res) {
                    return {
                        "code": res.success ? 0 : 300,
                        "count": res.data.total,
                        "data": res.data.list
                    }
                }
            });
        });
    }
</script>


</html>